import numpy as np
from sklearn.ensemble import RandomForestRegressor
from sklearn import metrics
import matplotlib.pyplot as plt # plt 用于显示图片

x_data= np.load('x_data.npy')
y_data= np.load('y_data.npy')
localtion= np.load('LOCATION.npy')
num_train=range(0,6)
num_test=range(5,20)
for i in num_train:
    print(x_data[i].shape)
    if i==num_train[0]:
        x_train=x_data[i]
        y_train = y_data[i]
    else:
        x_train=np.concatenate((x_train,x_data[i]), axis=0)
        y_train=np.concatenate((y_train, y_data[i]), axis=0)


print('训练数据大小',x_train.shape)

for i in num_test:
    print(x_data[i].shape)
    if i==num_test[0]:
        x_test = x_data[i]
        y_test = y_data[i]
    else:
        x_test=np.concatenate((x_test, x_data[i]), axis=0)
        y_test=np.concatenate((y_test, y_data[i]), axis=0)

print('测试数据大小',x_test.shape)

rf = RandomForestRegressor(n_estimators=1000)  # 这里使用了默认的参数设置
rf.fit(x_train, y_train)  # 进行模型的训练

y_predict = rf.predict(x_test)
y_predict [y_predict  >= 0.5] = 1
y_predict [y_predict  < 0.5] = 0

print(metrics.accuracy_score(y_test, y_predict))
np.save('Predict.npy', y_predict)









